<?php
	namespace Home\Controller;
	use Think\Controller;
	class LoginController extends Controller{
		   public function index(){
		   	
		   	// var_dump($_SESSION['user']);
		    	$this->display();
		    }
		    //处理登录
		    public function dologin(){
		    	//判断是否为空
		    	//接收数据
		    	$data['name'] = $_POST['name'];
		    	$data['poss']  = md5($_POST['poss']);
		    	// var_dump($data);

		    	$model = M('user');

				foreach ($data as $key => $value) {
				 	$where.="`$key`='$value' AND ";
				}
				 $where=trim($where,' AND ');
				 //find只查询一条
				 $res=$model->where($where)->find();
				 if (!$res) {
				 	$this->error('用户名或密码错误',U('Login/index'),1);
				 }
				 //var_dump($res);

				 //查询用户是否被禁用
				 $rest = $model->field('status')->where('id='.$res['id'])->find();
				 // var_dump($rest);exit;
				 if(!$rest['status']==0){
		    		//登录成功
		    		$_SESSION['user']=$res;
		    		//跳转到首页
		    		$this->success('登录成功',U('Index/index'),1);

		    	}else{
		    		if ($rest['status']==0) {
		    			$this->error('该用户已被禁用',U('Login/index'),1);
		    		}
		    	}
		    }

		    public function Loginout(){
		    	unset($_SESSION['user']);
		    	$this->success('退出成功',U('Index/index'),1);

		    }
	}